<div>
    <div class="row">
        <div class="col-md-8 offset-md-2">
            <h1>Registration</h1>

            <div class="alert alert-success" *ngIf="success">
                <strong>Registration saved!</strong> Please check your email for confirmation.
            </div>

            <div class="alert alert-danger" *ngIf="error">
                <strong>Registration failed!</strong> Please try again later.
            </div>

            <div class="alert alert-danger" *ngIf="errorUserExists">
                <strong>Login name already registered!</strong> Please choose another one.
            </div>

            <div class="alert alert-danger" *ngIf="errorEmailExists">
                <strong>Email is already in use!</strong> Please choose another one.
            </div>

            <div class="alert alert-danger" *ngIf="doNotMatch">
                The password and its confirmation do not match!
            </div>
        </div>
        <div class="col-md-8 offset-md-2">
            <form name="form" role="form" (ngSubmit)="register()" #registerForm="ngForm" *ngIf="!success">
                <div class="form-group">
                    <label class="form-control-label" for="login">Username</label>
                    <input type="text" class="form-control" [(ngModel)]="registerAccount.login" id="login" name="login" #login="ngModel" placeholder="Your username"
                            required minlength="1" maxlength="50" pattern="^[_'.@A-Za-z0-9-]*$">
                    <div *ngIf="login.dirty && login.invalid">
                        <small class="form-text text-danger" *ngIf="login.errors.required">
                            Your username is required.
                        </small>
                        <small class="form-text text-danger" *ngIf="login.errors.minlength"
                               >
                            Your username is required to be at least 1 character.
                        </small>
                        <small class="form-text text-danger" *ngIf="login.errors.maxlength"
                               >
                            Your username cannot be longer than 50 characters.
                        </small>
                        <small class="form-text text-danger" *ngIf="login.errors.pattern"
                              >
                            Your username can only contain lower-case letters and digits.
                        </small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="email">Email</label>
                    <input type="email" class="form-control" id="email" name="email" #email="ngModel" placeholder="Your email"
                            [(ngModel)]="registerAccount.email" minlength=5 maxlength=100 required>
                    <div *ngIf="email.dirty && email.invalid">
                        <small class="form-text text-danger" *ngIf="email.errors.required"
                               >
                            Your email is required.
                        </small>
                        <small class="form-text text-danger" *ngIf="email.errors.invalid"
                              >
                            Your email is invalid.
                        </small>
                        <small class="form-text text-danger" *ngIf="email.errors.minlength"
                              >
                            Your email is required to be at least 5 characters.
                        </small>
                        <small class="form-text text-danger" *ngIf="email.errors.maxlength"
                              >
                            Your email cannot be longer than 100 characters.
                        </small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="password">New password</label>
                    <input type="password" class="form-control" id="password" name="password" #password="ngModel" placeholder="New password"
                            [(ngModel)]="registerAccount.password" minlength=4 maxlength=50 required>
                    <div *ngIf="password.dirty && password.invalid">
                        <small class="form-text text-danger" *ngIf="password.errors.required"
                               >
                            Your password is required.
                        </small>
                        <small class="form-text text-danger" *ngIf="password.errors.minlength"
                               >
                            Your password is required to be at least 4 characters.
                        </small>
                        <small class="form-text text-danger" *ngIf="password.errors.maxlength"
                               >
                            Your password cannot be longer than 50 characters.
                        </small>
                    </div>
                    <jhi-password-strength-bar [passwordToCheck]="registerAccount.password"></jhi-password-strength-bar>
                </div>
                <div class="form-group">
                    <label class="form-control-label" for="confirmPassword">New password confirmation</label>
                    <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" #confirmPasswordInput="ngModel" placeholder="Confirm the new password"
                            [(ngModel)]="confirmPassword" minlength=4 maxlength=50 required>
                    <div *ngIf="confirmPasswordInput.dirty && confirmPasswordInput.invalid">
                        <small class="form-text text-danger" *ngIf="confirmPasswordInput.errors.required"
                              >
                            Your confirmation password is required.
                        </small>
                        <small class="form-text text-danger" *ngIf="confirmPasswordInput.errors.minlength"
                             >
                            Your confirmation password is required to be at least 4 characters.
                        </small>
                        <small class="form-text text-danger" *ngIf="confirmPasswordInput.errors.maxlength"
                              >
                            Your confirmation password cannot be longer than 50 characters.
                        </small>
                    </div>
                </div>

                <button type="submit" [disabled]="registerForm.form.invalid" class="btn btn-primary">Register</button>
            </form>
            <p></p>
            <div class="alert alert-warning">
                <span>If you want to </span>
                <a class="alert-link" (click)="openLogin()">sign in</a><span>, you can try the default accounts:<br/>- Administrator (login="admin" and password="admin") <br/>- User (login="user" and password="user").</span>
            </div>
        </div>
    </div>
</div>
